/**
 * Color Service
 * 颜色选择服务， 提供各类颜色处理效果
 */

angular.module('NxtMap')
  .service('ColorService', ColorService);

function ColorService() {

  //颜色变化计算 从绿到红
  this.getColorGR = function (v2, colorIndex) {
    if(v2 < colorIndex * 2){
      var red = v2 > colorIndex ? 0.9 : v2 / colorIndex;
      var green = v2 < colorIndex ? 0.64 : (colorIndex * 2 - v2) / colorIndex * 0.54 + 0.1;
    }
    else {
      var red = 1;
      var green = 0;
    }
    var blue = 0.3;
    return [red, green, blue];
  }

  //颜色变化计算 从黄到红
  this.getColorYR = function (v2, colorIndex) {
    var color = 2 * colorIndex;
    if(v2 < color){
      var red = (color - v2) / color * 0.1 + 0.9;
      var green = (color - v2) / color;
      var blue = (color - v2) / color * 0.51;
    }
    else {
      var red = 0.9;
      var green = 0;
      var blue = 0;
    }
    return [red, green, blue];
  }

  //颜色变化计算 从蓝到黄到红
  this.getColorBR = function (v2, colorIndex) {
    if(v2 < colorIndex * 2){
      var red = v2 > colorIndex ? (colorIndex * 2 - v2) / colorIndex * 0.1 + 0.9 : v2 / colorIndex * 0.9 + 0.1;
      var green = v2 > colorIndex ? (colorIndex * 2 - v2) / colorIndex * 0.9 + 0.1 : v2 / colorIndex * 0.5 + 0.5;
      var blue = (colorIndex * 2 - v2) / colorIndex * 0.3 + 0.1;
    }
    else {
      var red = 0.9;
      var blue = 0.1;
      var green = 0.1;
    }
    
    return [red, green, blue];
  }

  
}
